package com.dope_lh.myproject;

//public class MainActivity extends AppCompatActivity {
//
//    @FieldView(R.id.btn)
//    private Button btn;
//    @FieldView(R.id.tv)
//    private TextView tv;
//
//    @Override
//    protected void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_main);
//        ViewFind.bind(this);
//
//        btn.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                clickRequest("101010100");
//            }
//        });
//    }
//
//    private void clickRequest(String s) {
//        Retrofit retrofit = new Retrofit.Builder()
//                .baseUrl("http://www.weather.com.cn/")
//                .addConverterFactory(ScalarsConverterFactory.create())
//                .addConverterFactory(GsonConverterFactory.create())
//                .build();
//
//        ApiService apiService = retrofit.create(ApiService.class);
//
//        Call<WeatherBean> weatherBeanCall = apiService.requestWeather(s);
//
//        weatherBeanCall.enqueue(new Callback<WeatherBean>() {
//            @Override
//            public void onResponse(Call<WeatherBean> call, Response<WeatherBean> response) {
//                //请求成功
//                tv.setText(response.body().getWeatherinfo().toString());
//            }
//
//            @Override
//            public void onFailure(Call<WeatherBean> call, Throwable t) {
//
//            }
//        });
//    }
//}

//------------------------------------------------------------------------------------- demo1
//public class MainActivity extends AppCompatActivity implements RequestView1{
//    @FieldView(R.id.btn)
//    private Button   btn;
//    @FieldView(R.id.tv)
//    private TextView tv;
//    private RequestPresenter1 requestPresenter1;
//
//    @Override
//    protected void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_main);
//        ViewFind.bind(this);
//        requestPresenter1 = new RequestPresenter1(this);
//        btn.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                requestPresenter1.clickRequest("101010100");
//            }
//        });
//    }
//
//    @Override
//    public void requestLoading() {
//        tv.setText("加载中...");
//    }
//
//    @Override
//    public void resultSuccess(WeatherBean result) {
//        //成功
//        tv.setText(result.getWeatherinfo().toString());
//    }
//
//    @Override
//    public void resultFailure(String result) {
//        //成功
//        tv.setText(result);
//    }
//}

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.dope_lh.myproject.demo4.RequestPresenter4;
import com.dope_lh.myproject.demo4.RequestView4;
import com.dope_lh.myproject.demo4.base.AbstractMvpActivity;
import com.dope_lh.myproject.request.WeatherBean;
import com.dope_lh.myproject.utils.FieldView;
import com.dope_lh.myproject.utils.ViewFind;

//----------------------------------------------------------------------------------demo2
//public class MainActivity extends AppCompatActivity implements RequestView2 {
//    @FieldView(R.id.btn)
//    private Button            btn;
//    @FieldView(R.id.tv)
//    private TextView          tv;
//    private RequestPresenter2 presenter;
//
//    @Override
//    protected void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_main);
//        ViewFind.bind(this);
//        presenter = new RequestPresenter2();
//        presenter.attach(this);
//        btn.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                presenter.clickRequest("101010100");
//            }
//        });
//    }
//
//    @Override
//    public void requestLoading() {
//        tv.setText("加载中...");
//    }
//
//    @Override
//    public void resultSuccess(WeatherBean result) {
//        //成功
//        tv.setText(result.getWeatherinfo().toString());
//    }
//
//    @Override
//    public void resultFailure(String result) {
//        //成功
//        tv.setText(result);
//    }
//
//    @Override
//    protected void onDestroy() {
//        super.onDestroy();
//        presenter.detach();
//        presenter.interruptHttp();
//    }
//}

//------------------------------------------------------------------------demo4

public class MainActivity extends AbstractMvpActivity<RequestView4,RequestPresenter4> implements RequestView4 {

    @FieldView(R.id.btn)
    private Button            btn;
    @FieldView(R.id.tv)
    private TextView          tv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ViewFind.bind(this);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               getPresenter().clickRequest("101010100");
            }
        });
    }

    @Override
    protected RequestPresenter4 createPresenter() {
        return new RequestPresenter4();
    }

    @Override
    public void requestLoading() {
        tv.setText("加载中...");
    }

    @Override
    public void resultSuccess(WeatherBean result) {
        //成功
        tv.setText(result.getWeatherinfo().toString());
    }

    @Override
    public void resultFailure(String result) {
        //成功
        tv.setText(result);
    }

}


